home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / codecvt.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  5.0 KB  |  136 lines

  1. #ifndef __CODECVT_CC
  2. #define __CODECVT_CC
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4. /***************************************************************************
  5.  *
  6.  * codecvt.cc - Definitions for the Standard Library code conversion facet
  7.  *
  8.  *
  9.  ***************************************************************************
  10.  *
  11.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  12.  * ALL RIGHTS RESERVED *
  13.  * The software and information contained herein are proprietary to, and
  14.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  15.  * intends to preserve as trade secrets such software and information.
  16.  * This software is furnished pursuant to a written license agreement and
  17.  * may be used, copied, transmitted, and stored only in accordance with
  18.  * the terms of such license and with the inclusion of the above copyright
  19.  * notice.  This software and information or any other copies thereof may
  20.  * not be provided or otherwise made available to any other person.
  21.  *
  22.  * Notwithstanding any other lease or license that may pertain to, or
  23.  * accompany the delivery of, this computer software and information, the
  24.  * rights of the Government regarding its use, reproduction and disclosure
  25.  * are as set forth in Section 52.227-19 of the FARS Computer
  26.  * Software-Restricted Rights clause.
  27.  * 
  28.  * Use, duplication, or disclosure by the Government is subject to
  29.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  30.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  31.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  32.  * P.O. Box 2328, Corvallis, Oregon 97339.
  33.  *
  34.  * This computer software and information is distributed with "restricted
  35.  * rights."  Use, duplication or disclosure is subject to restrictions as
  36.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  37.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  38.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  39.  * then the "Alternate III" clause applies.
  40.  *
  41.  **************************************************************************/
  42.  
  43. #ifndef _RWSTD_NO_NAMESPACE
  44. namespace std {
  45. #endif
  46.  
  47. // -------------------------------------------------
  48. // Facet codecvt<internT,externT,stateT> member templates.
  49. // -------------------------------------------------
  50.  
  51. #ifndef _MSC_VER
  52. template <class internT,class externT,class stateT>
  53. locale::id codecvt<internT,externT,stateT>::id;
  54.  
  55. template <class internT,class externT,class stateT>
  56. codecvt<internT,externT,stateT>::~codecvt() {}
  57.  
  58. template <class internT, class externT, class stateT>
  59. codecvt_base::result
  60. codecvt<internT,externT,stateT>::do_out (stateT&,
  61.     const internT* from, const internT* from_end, const internT*& from_next
  62.    , externT* to, externT* to_end, externT*& to_next) const
  63. {
  64.   return noconv;
  65. }
  66.  
  67. template <class internT, class externT, class stateT>
  68. codecvt_base::result
  69. codecvt<internT,externT,stateT>::do_in (stateT&,
  70.     const externT* from, const externT* from_end, const externT*& from_next
  71.    , internT* to, internT* to_end, internT*& to_next) const
  72. {
  73.   return noconv;
  74. }
  75.  
  76. template <class internT,class externT,class stateT>
  77. bool codecvt<internT,externT,stateT>::do_always_noconv ()
  78.     const _RWSTD_THROW_SPEC_NULL
  79. {
  80.   return true;
  81. }
  82.  
  83. template <class internT,class externT,class stateT>
  84. int codecvt<internT,externT,stateT>::do_encoding()
  85.     const _RWSTD_THROW_SPEC_NULL
  86. {
  87.   return sizeof(internT) == sizeof(externT);
  88. }
  89.  
  90. template <class internT,class externT,class stateT>
  91. int codecvt<internT,externT,stateT>::do_length
  92.     (const stateT&, const internT *from, const internT *from_end, size_t max)
  93.     const
  94. {
  95.   return min (size_t(from_end-from), max);
  96. }
  97.  
  98. template <class internT,class externT,class stateT>
  99. int codecvt<internT,externT,stateT>::do_max_length ()
  100.     const _RWSTD_THROW_SPEC_NULL
  101. {
  102.   return 1;
  103. }
  104.  
  105. template <class internT,class externT,class stateT>
  106. _TYPENAME codecvt<internT,externT,stateT>::internal_string_type
  107. codecvt<internT,externT,stateT>::in (const external_string_type &s) const
  108. {
  109.   // Calculate the number of internT's that will be produced.  (I'm not sure
  110.   // what to use for max in the do_length call; too bad char_traits can't tell
  111.   // me.) (This needs to be revised to use separate in and out versions of
  112.   // do_length once someone comes up with the right syntax.)
  113.   int n=1000; // do_length(stateT(0),s.c_str(),s.c_str()+s.length(),
  114.               // numeric_limits<size_t>::max() / do_max_length());
  115.  
  116.   const externT *unused_from;
  117.   internT *unused_to;
  118.  
  119.   internT *conversion_buffer=new internT[n];
  120.   stateT stt(0);
  121.   n=do_in(stt,s.c_str(),s.c_str()+s.length(),unused_from,
  122.       conversion_buffer,conversion_buffer+n,unused_to);
  123.   internal_string_type result(conversion_buffer,conversion_buffer+n);
  124.   delete[] conversion_buffer;
  125.   return result;
  126. }
  127.  
  128. #endif // _MSC_VER
  129.  
  130. #ifndef _RWSTD_NO_NAMESPACE
  131. }
  132. #endif
  133.  
  134. #endif /* __CODECVT_CC */
  135. #pragma option pop
  136.